<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('拆箱单-修改')" />
	<th:block th:include="include :: businessCSS" />
	<style>
		.layui-table-tool{display: none;}
		.tablebody{background-color: #fff;padding: 20px;margin-right: 15px;}
		.tablebody input{display: inline;width: 80%;border: none;}
		.tablebody table{width: 100%;}
		.tablebody th,.tablebody td{border:solid 1px #ddd;padding:10px;font-size:14px;text-align: center;}
		.redcolor{color: red;cursor: pointer;min-width: 40px;}
		.bluecolor{color: rgb(71, 150, 253);cursor: pointer;min-width: 50px;}
	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
		<div class="north">
			<th:block th:include="include :: business_tpl('top')" />
		</div>
		<div style="padding: 16px;display: flex;justify-content: space-between;">
			<div  style="font-weight: 700;font-size: 18px;">拆箱单详情</div>
			<div>
				<button class="layui-btn layui-btn-normal dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" onclick="getMore('codeStockLocationPl',null,'货位编号','tcc_goodsallocation')" id="btn-sh">批量修改仓库信息</button>
			</div>
		</div>
		<div class="tablebody">
			<table class="zjtable">
				<thead>
				<tr>
					<th></th><th>商品编码</th><th>商品名称</th><th>实际发货数量</th>
					<th>货位编码</th><th>库区</th><th>所在仓库</th><th>上架数量</th><th>操作</th>
				</tr>
				</thead>
			</table>
		</div>
		<div th:if="${enableEdit==1}" style="bottom: 0;background-color: #fff;text-align:center; padding: 15px;">
			<input type="button" style="width: 100px;background: rgb(0, 135, 250);padding: 7px;color: #fff;border: none;border-radius: 10px;cursor: pointe" lay-submit lay-filter="btn-add" id="btn-add" value="保存">
		</div>
    </form>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />

<script th:inline="javascript">
	var fbaDevanningDetailList=[[${List}]]
	enableEdit =[[${enableEdit}]];
	var guidZb = $('#guid').val();
</script>

<script type="text/javascript">
	var $,layer,form,table,laydate,element;//定义layui模块
	layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
		$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
		$(document).ready(function(){
			var str=''
			if(fbaDevanningDetailList.length>0){
				for(var i=0;i<fbaDevanningDetailList.length;i++){
					str+='<tbody class="tbody">'
					for(var j=0;j<fbaDevanningDetailList[i].fbaDevanningDetailList.length;j++){
						if(j==0){
							str+=`<tr>
		    		    	<td class="redcolor" rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">+</td>
		    		    	<td class='fcommodityCode' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].commodityCode ?fbaDevanningDetailList[i].commodityCode :''}</td>
		    		    	<td class='fnameGoodsCn' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].nameGoodsCn ?fbaDevanningDetailList[i].nameGoodsCn :''}</td>
		    		    	<td class='fnumPlanDeliver' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].numPlanDeliver ?fbaDevanningDetailList[i].numPlanDeliver :''}</td>
		    		    	<td  hidden="hidden" class='frkGuid' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].rkGuid ?fbaDevanningDetailList[i].rkGuid :''}</td>
		    		    	<td  hidden="hidden" class='fvGsBm' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].vGsBm ?fbaDevanningDetailList[i].vGsBm :''}</td>
		    		    	<td  hidden="hidden" class='fguidKc' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].guidKc ?fbaDevanningDetailList[i].guidKc :''}</td>
		    		    	<td  hidden="hidden" class='fpriceIn' rowspan="${fbaDevanningDetailList[i].fbaDevanningDetailList.length}">${fbaDevanningDetailList[i].priceIn ?fbaDevanningDetailList[i].priceIn :''}</td>
		    		    	<td>
		    					<input type="text" name='codeStockLocation' readonly class='codeStockLocation' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockLocation ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockLocation :''}'>
		    					<i class="layui-icon layui-icon-more hlicon" onclick="getMore('codeStockLocation',null,'货位编号','tcc_goodsallocation')"></i>
		    				</td>
		    		    	<td><input type="text" name='codeStockArea' readonly class='codeStockArea' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockArea ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockArea :''}'></td>
		    		    	<td><input type="text" name='codeStockOn' readonly class='codeStockOn' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockOn ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockOn :''}'></td>
		    		    	<td><input type="number" name='numStorage' class='numStorage' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].numStorage ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].numStorage :''}'></td>
		    				<input type="hidden" name='guid' class='guid' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].guid}'>
							<input type="hidden" name='commodityCode' class='commodityCode' value='${fbaDevanningDetailList[i].commodityCode}'>
							<input type="hidden" name='nameGoodsCn' class='nameGoodsCn' value='${fbaDevanningDetailList[i].nameGoodsCn}'>
							<input type="hidden" name='numPlanDeliver' class='numPlanDeliver' value='${fbaDevanningDetailList[i].numPlanDeliver}'>
							<input type="hidden" name='guidKc' class='guidKc' value='${fbaDevanningDetailList[i].guidKc}'>
							<input type="hidden" name='rkGuid' class='rkGuid' value='${fbaDevanningDetailList[i].rkGuid}'>
							<input type="hidden" name='vGsBm' class='vGsBm' value='${fbaDevanningDetailList[i].vGsBm}'>
							<input type="hidden" name='priceIn' class='priceIn' value='${fbaDevanningDetailList[i].priceIn}'>
		    		    	<td style="color:#999;cursor:not-allowed;">删除</td>
		    		    </tr>`
						}else{
							str+=`<tr>
		    		    	<td>
		    					<input type="text" name='codeStockLocation' readonly class='codeStockLocation' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockLocation ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockLocation :''}'>
		    					<i class="layui-icon layui-icon-more hlicon" onclick="getMore('codeStockLocation',null,'货位编号','tcc_goodsallocation')"></i>
		    				</td>
		    		    	<td><input type="text" name='codeStockArea' readonly class='codeStockArea' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockArea ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockArea :''}'></td>
		    		    	<td><input type="text" name='codeStockOn' readonly class='codeStockOn' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockOn ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].codeStockOn :''}'></td>
		    		    	<td><input type="number" name='numStorage' class='numStorage' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].numStorage ?fbaDevanningDetailList[i].fbaDevanningDetailList[j].numStorage :''}'></td>
		    				<input type="hidden" name='guid' class='guid' value='${fbaDevanningDetailList[i].fbaDevanningDetailList[j].guid}'>
							<input type="hidden" name='commodityCode' class='commodityCode' value='${fbaDevanningDetailList[i].commodityCode}'>
							<input type="hidden" name='nameGoodsCn' class='nameGoodsCn' value='${fbaDevanningDetailList[i].nameGoodsCn}'>
							<input type="hidden" name='rkGuid' class='rkGuid' value='${fbaDevanningDetailList[i].rkGuid}'>
							<input type="hidden" name='vGsBm' class='vGsBm' value='${fbaDevanningDetailList[i].vGsBm}'>
							<input type="hidden" name='guidKc' class='guidKc' value='${fbaDevanningDetailList[i].guidKc}'>
							<input type="hidden" name='priceIn' class='priceIn' value='${fbaDevanningDetailList[i].priceIn}'>
		    		    	<td class="bluecolor">删除</td>
		    		    </tr>`
						}
					}
					str+='</tbody>'

				}
			}else{
				str+=`<tr><td colspan="10">暂无数据</td></tr>`
			}

			$('.zjtable').append(str)
	})

	var hlthis=''
	$('body').on('click','.hlicon',function(){
		hlthis=$(this)
	})
	window.getMoreAfter=function(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,res){
		if ( fields == 'codeStockLocationPl'){
			$('input[name="codeStockLocation"]').val(res.goodsAllocation);
			$('input[name="codeStockArea"]').val(res.goodsArea);
			$('input[name="codeStockOn"]').val(res.warehouseAddress);
		} else if ( fields == 'codeStockLocation'){
			hlthis.parent().parent().children().children('.codeStockLocation').val(res.goodsAllocation)
			hlthis.parent().parent().children().children('.codeStockArea').val(res.goodsArea)
			hlthis.parent().parent().children().children('.codeStockOn').val(res.warehouseAddress)
		}
	}

	// 添加行
	$('body').on('click','.redcolor',function(){
		var str=`<tr>
					<td>
						<input type="text" name='codeStockLocation' readonly class='codeStockLocation' value=''>
						<i class="layui-icon layui-icon-more hlicon" onclick="getMore('codeStockLocation',null,'货位编号','tcc_goodsallocation')"></i>
					</td>
					<td><input type="text" name='codeStockArea' readonly class='codeStockArea' value=''></td>
					<td><input type="text" name='codeStockOn' readonly class='codeStockOn' value=''></td>
					<td><input type="number" name='numStorage' class='numStorage' value=''></td>
					<input type="hidden" name='guid' class='guid' value=''}'>
					<input type="hidden" name='commodityCode' class='commodityCode' value='${$(this).nextAll(".fcommodityCode").text()}'>
					<input type="hidden" name='nameGoodsCn' class='nameGoodsCn' value='${$(this).nextAll(".fnameGoodsCn").text()}'>
					<input type="hidden" name='numPlanDeliver' class='numPlanDeliver' value='${$(this).nextAll(".fnumPlanDeliver").text()}'>
					<input type="hidden" name='guidKc' class='guidKc' value='${$(this).nextAll(".fguidKc").text()}'>
					<input type="hidden" name='rkGuid' class='rkGuid' value='${$(this).nextAll(".frkGuid").text()}'>
					<input type="hidden" name='vGsBm' class='vGsBm' value='${$(this).nextAll(".fvGsBm").text()}'>
					<input type="hidden" name='priceIn' class='priceIn' value='${$(this).nextAll(".fpriceIn").text()}'>
					<td class="bluecolor">删除</td>
				</tr>`
		$(this).attr('rowspan',+$(this).attr('rowspan')+1)
		$(this).nextAll("td").each(function(i){
			if($(this).attr('rowspan')){
				$(this).attr('rowspan',+$(this).attr('rowspan')+1)
			}
		})

		$(this).parent().parent().append(str)
	})


	// 删除行
	$('body').on('click','.bluecolor',function(){
		$(this).parent().remove();
	});
	form.on('submit(btn-add)', function(data){
		var daraArr=[]
		var isxd=true
		var iscc=true
		$('.tbody').each(function (i,s) {
			var a=''
			var addnum=0
			$(this).children('tr').each(function (v) {
				if($(this).children().children('.numStorage').val() == 0) iscc = false
				if(v==0) a=+$(this).children('.fnumPlanDeliver').text()
				addnum=addnum+(+$(this).children().children('.numStorage').val())
			})
			if(a!=addnum)isxd=false
		})
		if(!iscc)return layer.msg('上架数量不允许为0或者不允许为空!')
		if(!isxd)return layer.msg('上架数量不符')
		var isjx=true
		$('.tbody tr').each(function (i) {
			let obj={}
			obj.guid=$(this).children('.guid').val()
			obj.commodityCode=$(this).children('.commodityCode').val()
			obj.nameGoodsCn=$(this).children('.nameGoodsCn').val()
			obj.numPlanDeliver=$(this).children('.numPlanDeliver').val()
			obj.guidKc=$(this).children('.guidKc').val()
			obj.rkGuid=$(this).children('.rkGuid').val()
			obj.vGsBm=$(this).children('.vGsBm').val()
			obj.priceIn=$(this).children('.priceIn').val()

			obj.codeStockLocation=$(this).children().children('.codeStockLocation').val()
			obj.codeStockArea=$(this).children().children('.codeStockArea').val()
			obj.codeStockOn=$(this).children().children('.codeStockOn').val()
			obj.numStorage=$(this).children().children('.numStorage').val()
			if(!obj.codeStockLocation || !obj.numStorage)isjx=false
			daraArr.push(obj)
		})
		if(!isjx)return layer.msg('请填写货位编码和上架数量')
		data.field.guid = guidZb;
		$.operate.post("/logstics/fbaDevanning/editpost",{'infoMap':JSON.stringify(data.field),nid:$('#nid').val(),infoItems:JSON.stringify(daraArr)},function(res){
			layer.msg(res.msg)
			if(res.code==0){
				setTimeout(function(){
					window.location.reload();
				}, 1000);
			}

		})
	})
	})

</script>

</body>
</html>